define(function (require) {
    var $ = require('jquery');
    var Mustache = require('Mustache');
    var Tabs = require('./tabs').Tabs;
    var DeliveryService = require('./deliveryService').DeliveryService;
    var Recharge = require('./recharge').Recharge;
    var SmRecords = require('./smRecords').SmRecords;

    $(document).ready(function ($) {
        var serviceTabs = new Tabs('#nav .tabs-navs', '#content-bd');

        var deliveryService;

        var recharge;

        var smRecords;

        serviceTabs.on('change:activeIndex', function (val) {
            if (val == 1 && !deliveryService) {
                deliveryService = new DeliveryService();
            } else if (val == 2 && !recharge) {
                recharge = new Recharge();
            } else if (val == 3 && !smRecords) {
                smRecords = new SmRecords();
            }
        });

        serviceTabs.render();

        window.serviceTabs = serviceTabs;

        $(document.body).delegate('.recharge-btn', 'click', function (ev) {
            ev.preventDefault();

            if (!$(this).hasClass('.tabs-nav')) {
                serviceTabs.switchTo(2);

            }
        });

        $('#home-services a').each(function (index) {
            $(this).data('index', index + 1);
        });
        
        $('#home-services').delegate('a', 'click', function (ev) {
            var link = $(this);
            var switchTo = link.data('index');

            ev.preventDefault();

            if (!link.parents('.mod').hasClass('mod-disabled')) {
                serviceTabs.switchTo(switchTo);
            }
        });

        $('.service-active').click(function () {
            serviceTabs.switchTo(1);
        });


    });

});